<!DOCTYPE html>
<html>
<?php $this->load->view('admin/public/header.html');?>
<body class="childrenBody">
<form class="layui-form">
	<blockquote class="layui-elem-quote quoteBox">
		<form class="layui-form">
			<div class="layui-inline">
				<div class="layui-input-inline">
					<input type="text" class="layui-input searchVal" placeholder="请输入要搜索的技师名称" />
				</div>
				<a class="layui-btn search_btn" data-type="reload">搜索</a>
			</div>
			<!-- <div class="layui-inline">
				<a class="layui-btn layui-btn-normal addNews_btn">添加技师</a>
			</div>
			<div class="layui-inline">
				<a class="layui-btn layui-btn-danger layui-btn-normal delAll_btn">批量删除</a>
			</div> -->
		</form>
	</blockquote>
	
	
	
	<table id="newsList" lay-filter="newsList"></table>
	

	<!--操作-->
	<script type="text/html" id="newsListBar">
		<a class="layui-btn layui-btn-xs" lay-event="edit">查看详情</a>

		{{# if(d.issue==1){ }}
		<a class="layui-btn layui-btn-danger layui-btn-xs hide able{{d.issue}}" lay-event="disable">驳回审核</a>
		{{# }else if(d.issue==2){ }}
		<a class="layui-btn  layui-btn-xs layui-btn-normal  hide disable{{d.issue}}"  lay-event="able">通过审核</a>
		{{# }else if(d.issue==0){ }}
			
			<a class="layui-btn  layui-btn-xs layui-btn-normal  hide disable{{d.issue}}"  lay-event="able">通过审核</a>
			<a class="layui-btn layui-btn-danger layui-btn-xs hide able{{d.issue}}" lay-event="disable">驳回审核</a>

		{{# } }}
		
<!--
		<a class="layui-btn layui-btn-xs layui-btn-danger" lay-event="del">删除</a>
-->		
	</script>
</form>
<script type="text/javascript">
layui.config({
	  
	  debug: true //用于开启调试模式，默认false，如果设为true，则JS模块的节点会保留在页面
	});
layui.use(['form','layer','laydate','table','laytpl'],function(){
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer,
        $ = layui.jquery,
        laydate = layui.laydate,
        laytpl = layui.laytpl,
        table = layui.table;

    //列表
    var tableIns = table.render({
        elem: '#newsList',
        url : '<?php echo $dataurl?>',
        cellMinWidth : 95,
        page : true,
        height : "full-125",
        limit : 20,
        limits : [10,15,20,25],
        
        id : "newsListTable",
        cols : [[
                 {type: "checkbox", fixed:"left", width:50},
                 {field: 'technicianId', title: 'ID', width:100, align:"center",sort:true},
                 {field: 'realName', title: '技师姓名'}, 
                 {field: 'sevriceNo', title: '技师编号',sort:true},
                 {field: 'signature', title: '个性签名'},
                 
                
                 {title: '操作', width:300, templet:'#newsListBar',fixed:"right",align:"center"}
             ]],
             response: {
             	  statusName: 'code' //数据状态的字段名称，默认：code
             	  ,statusCode: 200 //成功的状态码，默认：0
             	  ,msgName: 'msg' //状态信息的字段名称，默认：msg
             	  ,countName: 'count' //数据总数的字段名称，默认：count
             	  ,dataName: 'data' //数据列表的字段名称，默认：data
             	}    
    });

    

    //搜索
    $(".search_btn").on("click",function(){
    	
    	table.reload("newsListTable",{
            page: {
                curr: 1 //重新从第 1 页开始
            },
            where: {
                search: $(".searchVal").val()  //搜索的关键字
            }
        })
        
        
    });

    //添加技师
    function addNews(edit){
        var index = layui.layer.open({
            title : "添加技师",
            type : 2,
            content : "<?php echo site_url('admin/technician/add')?>",		//iframe层时,这个参数传URL
            success : function(layero, index){
                var body = layui.layer.getChildFrame('body', index);
                if(edit){
                	body.find(".technicianId").val(edit.technicianId);
                    body.find('[name=realName]').val(edit.realName);
                    body.find('[name=phone]').val(edit.phone);
                    body.find('[name=jobId]').val(edit.jobId);                    
                    body.find('[name=intro]').val(edit.intro);
                    body.find('[name=tags]').val(edit.tags);
                    body.find('[name=signature]').val(edit.signature);
                    var avatar=edit.avatar;
                    var poster=edit.poster;
                    body.find('.avatar').val(avatar);
                    body.find('.avatarimg').attr('src','<?php echo IMAGEHOST?>'+avatar)
                    body.find('.poster').val(poster);
                    body.find('.posterimg').attr('src','<?php echo IMAGEHOST?>'+poster)
                    
                    for (i in edit.skill ){
						body.find('.tags[value='+edit.skill[i]+']').attr('checked',true);
                    }
                    form.render();
                }
                
                setTimeout(function(){
                    layui.layer.tips('点击返回', '.layui-layer-setwin .layui-layer-close', {
                        tips: 3
                    });
                },500)
            }
        })
        layui.layer.full(index);
        //改变窗口大小时，重置弹窗的宽高，防止超出可视区域（如F12调出debug的操作）
        $(window).on("resize",function(){
            layui.layer.full(index);
        })
    }
    $(".addNews_btn").click(function(){
        addNews();
    })

    //批量删除
    $(".delAll_btn").click(function(){
        var checkStatus = table.checkStatus('newsListTable'),
            data = checkStatus.data,
            technicianIds = [];
        //console.log(data);return;
        if(data.length > 0) {
            for (var i in data) {
            	technicianIds.push(data[i].technicianId);
            }
            layer.confirm('确定删除选中的技师？', {icon: 3, title: '提示信息'}, function (index) {
            	$.ajax({
                	type:'post',
                	data:{technicianIds:technicianIds},
                	dataType: "json", 
                	url:"<?php echo site_url('admin/technician/del')?>",
                	success:function(res){
                		if(res.code==200){
                			tableIns.reload();
                            layer.close(index);
                		}else{
                			layer.msg('删除失败');
                		}
                		
                        
                	},
                	fail:function(){
                		layer.msg('删除失败');
                	}
                })
            })
        }else{
            layer.msg("请选择需要删除的技师");
        }
    })

    //列表操作
    table.on('tool(newsList)', function(obj){
        var layEvent = obj.event,
            data = obj.data;		//技师数据
        if(layEvent === 'edit'){ //编辑
            addNews(data);
        }else if(layEvent === 'able'){ //通过
            layer.confirm('确定进行该操作吗？',{icon:3, title:'提示信息'},function(index){
            	console.log(data.companyId);
                $.ajax({
                	type:'post',
                	data:{technicianId:data.technicianId},
                	dataType: "json", 
                	url:"<?php echo site_url('admin/technician/able')?>",
                	success:function(res){
                		if(res.code==200){
                			obj.del();
                            layer.close(index);
                		}else{
                			layer.msg('操作失败');
                		}
                	},
                	fail:function(){
                		layer.msg('操作失败');
                	}
                })
                
            });
        }else if(layEvent === 'disable'){ //通过
            layer.confirm('确定进行该操作吗？',{icon:3, title:'提示信息'},function(index){
            	console.log(data.companyId);
                $.ajax({
                	type:'post',
                	data:{technicianId:data.technicianId},
                	dataType: "json", 
                	url:"<?php echo site_url('admin/technician/disable')?>",
                	success:function(res){
                		if(res.code==200){
                			obj.del();
                            layer.close(index);
                		}else{
                			layer.msg('操作失败');
                		}
                	},
                	fail:function(){
                		layer.msg('操作失败');
                	}
                })
                
            });
        }
    });

})

</script>
</body>
</html>